<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/myStrategyComment.css"/>
    <link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        $(function () {
            jQuery.ajaxSettings.traditional = true;
            /*获取get请求中带的参数*/
            var params = getParams();

            /*如果请求中没有攻略id,返回*/
            if (!params.strategyId) {
                return;
            }

            /*对该旅游地的评价,星星*/
            $(".star i").click(function () {
                var num = $(this).data('num');
                var children = $(".star").children("i");
                $(".star i").removeClass("fa-star").addClass("fa-star-o");
                for (let i = 0; i < num; i++) {
                    $(children[i]).addClass("fa-star");
                    $(children[i]).removeClass("fa-star-o");
                }
            })

            /*上传图片*/
            /*图片所在的div*/
            var rect;
            $(".rect").click(function () {
                rect = $(this);
                if (rect.html().indexOf("img") > -1) {
                    /*是否删除*/
                    $.confirm({
                        title: false,
                        content: '是否需要删除?',
                        buttons: {
                            confirm: {
                                text: '删除',
                                btnClass: 'btn-blue',
                                action: function () {
                                    rect.html('<span>上传</span>');
                                }
                            },
                            cancel: {
                                text: '取消'
                            }
                        }
                    })
                } else {
                    /*打开选择图片窗口*/
                    $('[name=file]').click();
                }
            })
            /*点击发送???*/
            $('[name=file]').change(function () {
                var img = $("[name=file]").val();
                if (img) {
                    $.ajax({
                        url: '/images',
                        type: 'POST',
                        data: new FormData($('#imgForm')[0]),
                        processData: false,
                        contentType: false,
                        success: function (data) {
                            if (data.status == 1) {
                                rect.html("<img width='100%' src='" + data.url + "'/>")
                            } else {
                                $(document).dialog({
                                    content: data.msg
                                });
                            }
                        }
                    });
                }
            });

            /*提交表单*/
            $("#submitBtn").click(function () {
                //获取评论的相关信息
                //星星
                var starNum = $(".fa-star").length;
                //评价内容
                var content = $("[name=content]").val();
                //图片
                var imgs = $(".imgs img");
                var imgUrls = "";
                for (let i = 0; i < imgs.length; i++) {
                    imgUrls += $(imgs[i]).attr('src') + ";";
                }


                var tagsArr = [];
                //系统推荐标签
                var sysTags = $("label.active").children();
                if (sysTags) {
                    for (var i = 0; i < sysTags.length; i++) {
                        var tagName = $(sysTags[i]).val();
                        tagsArr.push(tagName);
                    }
                }

                //自定义标签
                var myTags = $("[name=myTags]").val().split(" ");
                if (myTags) {
                    for (var j = 0; j < myTags.length; j++) {
                        if (myTags[j].trim() != "") {
                            tagsArr.push(myTags[j].trim());
                            i++;
                        }
                    }
                }
                var comment = {
                    starNum: starNum,
                    content: content,
                    imgUrls: imgUrls,
                    "strategy.id": params.strategyId,
                    tags: tagsArr
                };

                /*保存攻略评论*/
                $.post('/strategies/' + params.strategyId + '/comments',comment,

                function (data) {
                    if (data.success) {
                        window.location.href = "/strategyComment.html?commentId=" + data.result;
                    } else {
                        $(document).dialog({
                            content: data.msg
                        });
                    }
                })
            })
        })
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:window.history.go(-1)">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>

        </div>
        <div class="col">
            <span>点评</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<div class="comment">
    <div class="container star">
        <p>你对该旅游地的评价</p>
        <i class="fa fa-star-o fa-lg" data-num="1"></i>
        <i class="fa fa-star-o fa-lg" data-num="2"></i>
        <i class="fa fa-star-o fa-lg" data-num="3"></i>
        <i class="fa fa-star-o fa-lg" data-num="4"></i>
        <i class="fa fa-star-o fa-lg" data-num="5"></i>
    </div>
    <hr/>
    <div class="container tag">
        <p>请为该旅游地选择合适的标签（大家都在评）</p>
        <div class="btn-group-toggle" data-toggle="buttons">
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="价格便宜"> 价格便宜
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="住宿方便"> 住宿方便
            </label>
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="旅游景点多"> 旅游景点多
            </label>
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="适合拍照">适合拍照
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="吃的很多">吃的很多
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="交通不方便">交通不方便
            </label>
        </div>

        <p>添加你自己的标签</p>
        <input name="myTags" class="form-control" placeholder="请使用空格隔开标签，每个标签不超8个字"/>

        <p>更多评价内容</p>
        <textarea name="content" class="form-control" rows="5" placeholder="请填写你对该旅游地的评价"></textarea>
    </div>
    <div class="container imgs ">
        <p>上传图片</p>

        <div class="row">
            <form id="imgForm" method="post" enctype="multipart/form-data">
                <input type="file" style="display: none" name="file"/>
            </form>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
        </div>
    </div>

</div>


<div class="operation">
    <button class="btn" onclick="window.history.go(-1)">放弃评价</button>
    <button class="btn" id="submitBtn">提交评价</button>
</div>


</body>


</html>